Skip to content

Reclaim orphaned pool connections after cancellation#1094

Open
tianrking wants to merge 1 commit into
encode:masterfrom
tianrking:agent/reclaim-cancelled-pool-connections
Open

Reclaim orphaned pool connections after cancellation#1094
tianrking wants to merge 1 commit into
encode:masterfrom
tianrking:agent/reclaim-cancelled-pool-connections

Conversation

@tianrking

Copy link
Copy Markdown

Fixes #1093

Summary

  • Reclaim a non-idle connection when no remaining pool request owns it.
  • Apply the same cleanup invariant to the synchronous and asynchronous pools.
  • Add an async regression that cancels a request after assignment but before dispatching it to the connection.

Root cause

A cancelled async request can be removed after receiving a newly created connection but before calling that connection. The connection is neither idle nor closed, and no longer belongs to any request, so it remains in the pool and consumes a connection slot indefinitely.

Validation

  • python -m ruff format httpcore tests --check
  • python -m ruff check httpcore tests
  • python -m mypy httpcore/_async/connection_pool.py httpcore/_sync/connection_pool.py tests/_async/test_connection_pool.py
  • python -m pytest -q (216 passed, 6 xpassed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cancelling requests under pool contention permanently leaks connection slots (AsyncConnectionPool → PoolTimeout)

1 participant